package org.abettor.angleworm.media;

import javax.media.CaptureDeviceInfo;
import javax.media.Processor;
import javax.media.format.UnsupportedFormatException;
import javax.media.protocol.ContentDescriptor;

/**
 * 视频媒体捕获程序类
 * @author abettor
 *
 */
public class VideoMediaCapture extends MediaCapture
{
	/**
	 * @see org.abettor.angleworm.media.MediaCapture#MediaCapture(CaptureDeviceInfo, ContentDescriptor)
	 */
	public VideoMediaCapture(CaptureDeviceInfo device, ContentDescriptor descriptor)
	{
		super(device, descriptor);
	}

	/**
	 * @see org.abettor.angleworm.media.MediaCapture#format(Processor)
	 */
	@Override
	protected void format(Processor processor) throws UnsupportedFormatException
	{
		//TODO	设定要输出的视频格式
	}

	/**
	 * @see org.abettor.angleworm.media.MediaCapture#closeCapture()
	 */
	@Override
	public void closeCapture() throws InterruptedException
	{
		//	首先调用父类方法
		super.closeCapture();

		//	鉴于实测发现处理器关闭后有线程不会退出，故强行结束之（技巧）
		ThreadGroup tg = Thread.currentThread().getThreadGroup();
		Thread[] threads = new Thread[tg.activeCount()];
		tg.enumerate(threads);
		for(Thread thrd : threads)
		{
			if(! thrd.isDaemon())
			{
				if("AWT-Shutdown".equals(thrd.getName()) || "AWT-EventQueue-0".equals(thrd.getName()))
				{
					thrd.interrupt();
				}
			}
		}
	}
}
